//
//  CZNearbyController.m
//  YingKeLive
//
//  Created by 西瓜大浪 on 2021/9/2.
//

#import "CZNearbyController.h"
#import "CZTopicListCell.h"
@interface CZNearbyController () <UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,strong)UICollectionView *collectionView;

@end
static NSString *const CZTopicListCellid =@"CZTopicListCell";

@implementation CZNearbyController

- (void)viewDidLoad {
    [super viewDidLoad];
    //layout
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = [UIScreen mainScreen].bounds.size;//cell大小
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;//左右滑动
    flowLayout.minimumLineSpacing = 0;
//    flowLayout.minimumInteritemSpacing = 0;
    
    
    //collectionView
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flowLayout];
    collectionView.backgroundColor = [UIColor orangeColor];
    collectionView.dataSource = self;
    collectionView.delegate = self;
    collectionView.pagingEnabled = YES;//分页

    
    
    //注册cell
    UINib *nib = [UINib nibWithNibName:NSStringFromClass([CZTopicListCell class]) bundle:nil];
    [collectionView registerNib:nib forCellWithReuseIdentifier:CZTopicListCellid];
    [self.view addSubview:collectionView];
    
    
    

}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return  10;
    
}

-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CZTopicListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CZTopicListCellid forIndexPath:indexPath];
    
    
        
    cell.backgroundColor = randomRGB;
    
    return  cell;
   
}

#pragma mark - <UICollectionViewDelegate>
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@"%d", (int)(scrollView.contentOffset.x / scrollView.frame.size.width));
    
    
}


@end
